﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace Arthus
{
    public partial class kontaktForma : Form
    {
        private String idPartnera, idKontakta;
        public kontaktForma(String partnerID, String kontaktID)
        {
            InitializeComponent();
            this.idPartnera = partnerID;
            this.idKontakta = kontaktID;
        }
        Partneri partneriObjekat = null;
        private void ProveraPostojanostiKontakta() {
            if (idKontakta.Length > 0)
            {
                buttonDodaj.Enabled = false;
                buttonIzmeni.Enabled = true;
            }
            else {
                buttonDodaj.Enabled = true;
                buttonIzmeni.Enabled = false;
            }
        }

        private void kontaktForma_Load(object sender, EventArgs e)
        {
            partneriObjekat = new Partneri();
            partneriObjekat.PopuniKontroleUKontaktFormi(idKontakta, textBoxIme, textBoxTelefon, textBoxFax, textBoxInternet, textBoxEmail, textBoxNapomena);
            ProveraPostojanostiKontakta();
        }

        private void buttonZatvori_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void buttonDodaj_Click(object sender, EventArgs e)
        {
            partneriObjekat = new Partneri();
            partneriObjekat.DodajIliIzmeniKontakt(idKontakta, idPartnera, textBoxIme, textBoxTelefon, textBoxInternet, textBoxEmail, textBoxNapomena, textBoxFax);
            textBoxIme.Text = "";
            textBoxTelefon.Text = "";
            textBoxFax.Text = "";
            textBoxInternet.Text = "";
            textBoxEmail.Text = "";
            textBoxNapomena.Text = "";
            textBoxIme.Focus();
        }

        private void buttonIzmeni_Click(object sender, EventArgs e)
        {
            partneriObjekat = new Partneri();
            partneriObjekat.DodajIliIzmeniKontakt(idKontakta, idPartnera, textBoxIme, textBoxTelefon, textBoxInternet, textBoxEmail, textBoxNapomena, textBoxFax);
        }

        private void TABKaoENTER(KeyEventArgs e)
        {
            if (e.KeyData == Keys.Enter)
            {
                e.SuppressKeyPress = true;
                SelectNextControl(ActiveControl, true, true, true, true);
            }
        }
        private void textBoxIme_KeyDown(object sender, KeyEventArgs e)
        {
            TABKaoENTER(e);
        }
        private void textBoxTelefon_KeyDown(object sender, KeyEventArgs e)
        {
            TABKaoENTER(e);
        }
        private void textBoxFax_KeyDown(object sender, KeyEventArgs e)
        {
            TABKaoENTER(e);
        }
        private void textBoxInternet_KeyDown(object sender, KeyEventArgs e)
        {
            TABKaoENTER(e);
        }
        private void textBoxEmail_KeyDown(object sender, KeyEventArgs e)
        {
            TABKaoENTER(e);
        }
        private void textBoxNapomena_KeyDown(object sender, KeyEventArgs e)
        {
            TABKaoENTER(e);
        }
    }
}
